//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {},
    addres: {},
    city:"",
    weather_data: {},
  },
  //事件处理函数
  bindViewTap: function(e) {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },
  btn_map:function(e){
   // 打开微信地图
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          scale: 28
        })
      }
    })
  },
  //页面跳转
  btn_redirectTo:function(e){
     wx.redirectTo({
       url: "test/test"
     })
  },
  onLoad: function () {
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        var ads = res;
        var latitude = res.latitude
        var longitude = res.longitude
        wx.request({
          url: 'https://api.map.baidu.com/telematics/v3/weather?coord_type=gcj02&output=json&ak=F7du3LGgbioQaRUcGLBGU8nH1GMciGW4&sn=&timestamp=&location=' + longitude+'%2C' + latitude+'',
          header: {'content-type': 'application/json'},
          success:function(res){
            that.setData({
              addres:ads,
              city: res.data.results[0].currentCity,
              weather_data: res.data.results[0].weather_data
            })
          }
        })
      }
    })
  }
})
